﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Text;
using Abp.Application.Services.Dto;
using Abp.AutoMapper;
using Abp.Domain.Entities;
using FwProject.Comm.ExcelUtil;
using FwProject.Core.Distribution;
using FwProject.Core.Restaurant;
using FwProject.Core.SettlementInfoModel;
using X.PagedList;

namespace FwProject.Distribution.Dto
{
    [DisplayName(displayName: "应收查询")]
    public class ReceivableDto : Entity<Guid>
    {
        [Display(Name = "所属工厂")]
        public Guid FactoryinfoId { get; set; }

        [Display(Name = "餐厅名称")]
        [DisplayName(displayName: "餐厅名称")]
        [ExcelDateMember]
        public string RestaurantName { get; set; }

        [Display(Name = "餐厅地址")]
        [DisplayName(displayName: "餐厅地址")]
        [ExcelDateMember]
        public string RestaurantAddress { get; set; }

        [Display(Name = "配送司机")]
        [DisplayName(displayName: "配送司机")]
        [ExcelDateMember]
        public string DriverName { get; set; }

        [Display(Name = "车牌号")]
        [DisplayName(displayName: "车牌号")]
        [ExcelDateMember]
        public string PlatesNumber { get; set; }

        [Display(Name = "司机手机")]
        [DisplayName(displayName: "司机手机")]
        [ExcelDateMember]
        public string DriverMobile { get; set; }

        [Display(Name = "配送时间")]
        public DateTime CreationTime { get; set; }

        public long CreatorUserId { get; set; }

        [Display(Name = "支付状态")]
        [DisplayName(displayName: "支付状态")]
        [ExcelDateMember]
        public Pricestatus Pricestatus { get; set; }

        [Display(Name = "应收金额")]
        [DisplayName(displayName: "应收金额")]
        [ExcelDateMember(IsSum = true)]
        public decimal TotalPrice { get; set; }
    }

    [DisplayName(displayName:"应收查询")]
    [AutoMap(typeof(SettlementInfo))]
    public class ReceivableNewOutputDto : EntityDto<Guid>
    {
        /// <summary>
        /// 状态
        /// </summary>
        [DisplayName(displayName:"状态")]
        [ExcelDateMember]
        public RestaurantPayStatus RestaurantPayStatus { get; set; }

        /// <summary>
        /// 应收类型
        /// </summary>
        [DisplayName(displayName: "应收类型")]
        [ExcelDateMember]
        public BalanceWayEnum BalanceWayEnum { get; set; }

        /// <summary>
        /// 餐厅名称
        /// </summary>
        [DisplayName(displayName: "餐厅名称")]
        [ExcelDateMember]
        public string RestaurantName { get; set; }

        /// <summary>
        /// 司机Id
        /// </summary>
        public long? Driverid { get; set; }

        /// <summary>
        /// 司机名称
        /// </summary>
        public string DriverName { get; set; }

        public long? CreatorUserId { get; set; }

        /// <summary>
        /// 开单日期
        /// </summary>
        [DisplayName(displayName: "开单日期")]
        [ExcelDateMember]
        public DateTime CreationTime { get; set; }

        /// <summary>
        /// 单号
        /// </summary>
        [DisplayName(displayName: "单号")]
        [ExcelDateMember]
        public string CreationNumber { get; set; }

        /// <summary>
        /// 配送日期
        /// </summary>
        [DisplayName(displayName: "配送日期")]
        [ExcelDateMember]
        public string DeliveryDate { get; set; }

        public DateTime? BeginTime { get; set; }

        public DateTime? EndTime { get; set; }

        /// <summary>
        /// 应收金额
        /// </summary>
        [DisplayName(displayName: "整单金额")]
        [ExcelDateMember(IsSum =true)]
        public decimal Totalprice { get; set; }

        /// <summary>
        /// 实际金额
        /// </summary>
        [DisplayName(displayName: "应收金额")]
        [ExcelDateMember(IsSum =true)]
        public decimal Actualprice { get; set; }

        /// <summary>
        /// 实际收款金额
        /// </summary>
        [DisplayName(displayName: "已收金额")]
        [ExcelDateMember(IsSum =true)]
        public decimal ReceivedPrice { get; set; }

        /// <summary>
        /// 未收金额
        /// </summary>
        [DisplayName(displayName: "未收金额")]
        [ExcelDateMember(IsSum =true)]
        public decimal TaskNotBackAmount { get { return Totalprice - ReceivedPrice - TotalDiscount - UsePrePayment; } }

        /// <summary>
        /// 使用预收款
        /// </summary>
        
        public decimal UsePrePayment { get; set; }

        /// <summary>
        /// 制单优惠
        /// </summary>
        /// <value>The discountprice.</value>
        [DisplayName(displayName: "制单优惠")]
        [ExcelDateMember(IsSum =true)]
        public decimal Discountprice { get; set; }

        /// <summary>
        /// 收款优惠
        /// </summary>
        [DisplayName(displayName: "收款优惠")]
        [ExcelDateMember(IsSum =true)]
        public decimal ReceivedDiscount { get; set; }

        /// <summary>
        /// 总优惠
        /// </summary>
        [DisplayName(displayName: "总优惠")]
        [ExcelDateMember(IsSum =true)]
        public decimal TotalDiscount { get { return Discountprice + ReceivedDiscount; } }

        /// <summary>
        /// 折扣率
        /// </summary>
        [DisplayName(displayName: "折扣率")]
        [ExcelDateMember]
        public string DiscountRate { get { return (Convert.ToDouble(TotalDiscount) / Convert.ToDouble(Totalprice)).ToString("0.00%"); } }



    }


    public class ReceivableNewSummaryDto
    {
        /// <summary>
        /// 整单合计
        /// </summary>
        public decimal SumTotalPrice { get; set; }

        /// <summary>
        /// 应收合计
        /// </summary>
        public decimal SumActualPrice { get; set; }

        /// <summary>
        /// 已收合计
        /// </summary>
        public decimal SumReceivedPrice { get; set; }

        /// <summary>
        /// 未收合计
        /// </summary>
        public decimal SumTaskNotBackAmount { get; set; }

        /// <summary>
        /// 制单优惠合计
        /// </summary>
        public decimal SumDiscountPrice { get; set; }

        /// <summary>
        /// 收款优惠合计
        /// </summary>
        public decimal SumReceivedDiscount { get; set; }

        /// <summary>
        /// 优惠合计
        /// </summary>
        public decimal SumTotalDiscount { get; set; }

        public IPagedList<ReceivableNewOutputDto> PageList { get; set; }
    }
}
